Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding Ergast filter parameters #489

Merged
merged 8 commits into from
Dec 26, 2023
Merged

Expanding Ergast filter parameters #489

merged 8 commits into from
Dec 26, 2023

Conversation

Lombardoc4
Copy link
Contributor

The _build_url function leads to an error by adding an additional parameter "endpoint" to the end of the filename for every case. Which leads to ErgastInvalidRequestError

The warning can be found here:
"Only some combinations of filter parameters are possible and those vary for each API endpoint. FastF1 does not impose restrictions on these combinations as the relationships are fairly complex. Instead, an ErgastInvalidRequestError will be returned in such a case. The exception will contain the error response of the server."

Expected: https://ergast.com/api/f1/2023/drivers/alonso.json
Received: https://ergast.com/api/f1/2023/drivers/alonso/drivers.json

This endpoint needs to be present if no filters are applied or if only season or round filters are used. If any additional filter params are present, we omit the endpoint param, returning a valid URL

@theOehrly
Copy link
Owner

theOehrly commented Dec 14, 2023

Hi, thanks for noting this problem and opening this PR.

I do see some issues with the approach that you have chosen to fix this, though. First, given that multiple selectors can be combined, baseJson can be inverted multiple times, resulting in incorrect behaviour. Second, when for example a driver selector is combined with the laps endpoint, the endpoint still needs to be included. This is not the case with your solution.

I suggest instead that the drivers endpoint is implemented similarly to, for example, the laps endpoint. In fact, the drivers, constructors, circuits and status endpoint need to be implemented in this way. Do you want to update your PR? Please also adhere to the PEP8 style guidelines.

@Lombardoc4
Copy link
Contributor Author

I've updated the commit on this. I see what you're suggesting this behavior is already in place for a few endpoints, such as lap. I mimicked the behavior over into the recommended endpoints you provided. This allowed us to completely remove baseJson

@Lombardoc4
Copy link
Contributor Author

After reinvestigating the failure it seems that there is some complexity to wrap my head around.

  • The order of the selectors is meaningful
  • The endpoint value is specific to a call e.g get_circuit_info()
  • With certain endpoints the postfix is necessary e.g "circuits"
  • With certain combinations the postfix is not necessary e.g season & round

Theoretically I need to further mimic the laps

@theOehrly
Copy link
Owner

Yes, exactly. The API endpoint structure is not very consistent.

@Lombardoc4
Copy link
Contributor Author

Lombardoc4 commented Dec 20, 2023

Noting saw docs with amend future commits
(Summary for PR Authors)

Is this a breaking change, considering the changes alter the data from ergast?

I've altered the calls to replicate the function you shared.
There is one addition for conditional implemented for get_race_schedule.
These are two examples from ergast, you can notice one has the races endpoint while the others omit it.

https://ergast.com/api/f1/2012
https://ergast.com/api/f1/2008/5
https://ergast.com/api/f1/drivers/alonso/circuits/monza/races

Don't think I got this part perfected. I need to use something alternative besides selector length.
As you can see in the second example call there is a value for round, this will currently trigger the appending of /races

@theOehrly
Copy link
Owner

Is this a breaking change, considering the changes alter the data from ergast?

No, the current behaviour is incorrect, therefore this is a bug fix.

I'll have a look at everything and do some manual testing, and then I'll get back to you.

@theOehrly
Copy link
Owner

I pushed some minor changes to your branch and added more tests. Everything looks good now. Thank you for noticing this issue and for helping to fix it.

@theOehrly theOehrly merged commit 3474b03 into theOehrly:master Dec 26, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants